﻿#include "B3PanelTestLamp.h"
#include "OPTMV_LED/OptmvLampControl.h"
#include "ART3062/Art3062LampControl.h"
#include <QDebug>
void TopIlluminator::loadSettings(QSettings &settings)
{
    m_IP = settings.value("ARTLED/IP", "192.168.2.80").toString();
    m_port = settings.value("ARTLED/Port", 502).toInt();
    m_channelIndex = settings.value("ARTLED/ChannelNum", "1").toInt();
    m_lens = settings.value("LENS/Lens", 0).toInt();
    Art3062LampControl *control = new Art3062LampControl;
    control->connectDevice(m_IP, m_port);
    m_pControl = control;
}

int TopIlluminator::value()
{
    qDebug() << "TopIlluminator::value()";
    if(!m_pControl) return 0;
    int v = m_pControl->value(m_channelIndex);
    m_brightness[m_lens] = v / 16;
    return m_brightness[m_lens];
}

void TopIlluminator::setValue(int value)
{
    if(m_brightness[m_lens] == value) return;
    m_brightness[m_lens] = value;
    if(m_pControl)
    {
        m_pControl->setValue(m_channelIndex, value * 16);
        emit valueChanged(value);
    }
}

void TopIlluminator::turnOnOff(bool on)
{
    if(m_pControl) m_pControl->setEnable(m_channelIndex, on);
}

void BottomIlluminator::loadSettings(QSettings &settings)
{
    m_channelIndex = settings.value("OPTLED/ChannelIndex", "1").toInt();
    m_comPort = settings.value("OPTLED/SerialPort", "COM3").toString();
    m_lens = settings.value("LENS/Lens", 0).toInt();
    OptmvLampControl * control = new OptmvLampControl;
    control->connectBySerialPort(m_comPort);
    m_pControl = control;
}

int BottomIlluminator::value()
{
    qDebug() << "BottomIlluminator::value()";
    if(!m_pControl) return 0;
    m_brightness[m_lens] = m_pControl->value(m_channelIndex);
    return m_brightness[m_lens];
}

void BottomIlluminator::setValue(int value)
{
    if(m_brightness[m_lens] == value) return;
    m_brightness[m_lens] = value;
    if(m_pControl)
    {
        m_pControl->setValue(m_channelIndex, value);
        emit valueChanged(value);
    }
}

void BottomIlluminator::turnOnOff(bool on)
{
    if(m_pControl) m_pControl->setEnable(m_channelIndex, on);
}
